//
//  CTDiscoveryView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/5/23.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTDiscoveryView.h"
#import "CTDebugManager.h"
#import "CTHeader.h"
#import "CTDVSwitch.h"
#import "CTAppLanguage.h"
#import "UIViewAdditions.h"
#import "CTFollowView.h"
#import "CTUserPublishTableListView.h"

@interface CTDiscoveryView ()<CTUserPublishTableListViewDelegate>
{
    UIView * topView;
    
    CTFollowView * followView;
   
    
    CTUserPublishTableListView * userPublishTableListView;
}

@end

@implementation CTDiscoveryView
@synthesize delegate;


- (void)dealloc
{
    [topView removeFromSuperview];
    topView = nil;
    delegate = nil;
    
    [userPublishTableListView removeFromSuperview];
    userPublishTableListView = nil;
    
    [followView removeFromSuperview];
    followView = nil;
    
    
    [CTDebugManager showDebugLogInfo:@"dealloc : CTDiscoveryView Is Removed!!!"];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT);
        self.backgroundColor = CT_HEADER_WHITE_COLOR;
        
        [self creatSubviews];
    }
    return self;
}

-(void)creatSubviews
{
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
    //    topView.alpha = 0.8;
    [self addSubview:topView];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, CT_HEADER_SCREEN_WIDTH, 44)];
    titleLabel.text = [CTAppLanguage localizedStringForKey:@"discoveryView_title_text" withValue:nil withTable:@"Language"];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = CT_HEADER_GREEN_COLOR;
    titleLabel.font = [UIFont fontWithName:nil size:19];
    [topView addSubview:titleLabel];
    UILabel *topLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topLine];
    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topBottomLine];
    
    
//    followView = [[CTFollowView alloc] init];
//    followView.delegate = self;
//    [self addSubview:followView];
    
   
    userPublishTableListView = [[CTUserPublishTableListView alloc] initWithFrame:CGRectMake(0,64, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT-64-50)];
    userPublishTableListView.delegate = self;
    [self addSubview:userPublishTableListView];

    
}


#pragma mark - action & delegate -

-(void)reloadData
{
    [userPublishTableListView reloadData];
}

-(void)refresh
{
    [userPublishTableListView refresh];
}

-(void)refreshPullDownEnd
{
    [userPublishTableListView refreshPullDownEnd];
}
-(void)refreshPullUpEnd
{
    [userPublishTableListView refreshPullUpEnd];
}



#pragma mark - setter -


-(void)setFollowListArr:(NSArray *)followListArray
{
    userPublishTableListView.pubDataArray = followListArray;
}

-(void)setSugesstionUserListArr:(NSArray *)suggestionUserListArray
{
    userPublishTableListView.recommendListArray = suggestionUserListArray;
}


#pragma mark - follow view delegate -


-(void)refreshControlPullDown:(CTUserPublishTableListView *)view
{
    if ([self.delegate respondsToSelector:@selector(refreshPullDown:)]) {
        [self.delegate refreshPullDown:self];
    }
}

-(void)refreshControlPullUp:(CTUserPublishTableListView *)view
{
    if ([self.delegate respondsToSelector:@selector(refreshPullUp:)]) {
        [self.delegate refreshPullUp:self];
    }
}


/**
 *@brief 点击评论总数
 */
- (void)userPublishTableListCommentCountAction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(commentCountAction:withItem:)]) {
        [self.delegate commentCountAction:self withItem:item];
    }
}
/**
 *@brief 点击评论第一条
 */
- (void)userPublishTableListCommentHitFirstLabelAction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(commentHitFirstLabelAction:withItem:)]) {
        [self.delegate commentHitFirstLabelAction:self withItem:item];
    }
}
/**
 *@brief 点击评论第二条
 */
- (void)userPublishTableListCommentHitSecondLabelAction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(commentHitSecondLabelAction:withItem:)]) {
        [self.delegate commentHitSecondLabelAction:self withItem:item];
    }
}
/**
 *@brief 点击评论第一条头像
 */
- (void)userPublishTableListCommentHitFirstHeadAction:(CTUserPublishTableListView *)view withItem:(CTComment *)item
{
    if ([self.delegate respondsToSelector:@selector(commentHitFirstHeadAction:withItem:)]) {
        [self.delegate commentHitFirstHeadAction:self withItem:item];
    }
}
/**
 *@brief 点击评论第二条头像
 */
- (void)userPublishTableListCommentHitSecondHeadAction:(CTUserPublishTableListView *)view withItem:(CTComment *)item
{
    if ([self.delegate respondsToSelector:@selector(commentHitSecondHeadAction:withItem:)]) {
        [self.delegate commentHitSecondHeadAction:self withItem:item];
    }
}
/**
 *@brief 点击头像
 */
- (void)userPublishTableListHitHeadAction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(hitHeadAction:withItem:)]) {
        [self.delegate hitHeadAction:self withItem:item];
    }
}
/**
 *@brief 点击大图
 */
- (void)userPublishTableListHitPicImageBtnAction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item withImageView:(UIImageView *)picImageView
{
    if ([self.delegate respondsToSelector:@selector(hitPicImageBtnAction:withItem:withImageView:)]) {
        [self.delegate hitPicImageBtnAction:self withItem:item withImageView:picImageView];
    }
}
/**
 *@brief 点赞
 */
- (void)userPublishTableListHitFavourBtnAction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item withBool:(BOOL)favBool
{
    if ([self.delegate respondsToSelector:@selector(hitFavourBtnAction:withItem:withBool:)]) {
        [self.delegate hitFavourBtnAction:self withItem:item withBool:favBool];
    }
}
/**
 *@brief 点击评论按钮
 */
- (void)userPublishTableListHitCommentBtnaction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(hitCommentBtnaction:withItem:)]) {
        [self.delegate hitCommentBtnaction:self withItem:item];
    }
}
/**
 *@brief 点击分享按钮
 */
- (void)userPublishTableListHitShareBtnAction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item withImage:(UIImage *)img
{
    if ([self.delegate respondsToSelector:@selector(hitShareBtnAction:withItem: withImage:)]) {
        [self.delegate hitShareBtnAction:self withItem:item withImage:img];
    }
}
/**
 *@brief 点击更多按钮
 */
- (void)userPublishTableListHitMoreBtnAction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(hitMoreBtnAction:withItem:)]) {
        [self.delegate hitMoreBtnAction:self withItem:item];
    }
}
/**
 *@brief 点击点赞的人的头像
 */
- (void)userPublishTableListHitFavBtnHeadAction:(CTUserPublishTableListView *)view withItem:(CTListDetailUser *)item
{
    if ([self.delegate respondsToSelector:@selector(hitFavBtnHeadAction:withItem:)]) {
        [self.delegate hitFavBtnHeadAction:self withItem:item];
    }
}
/**
 *@brief 点击关注按钮
 */
- (void)userPublishTableListHitAttentionBtnAction:(CTUserPublishTableListView *)view withItem:(CTFollowList *)item withBool:(BOOL)attenBool
{
    if ([self.delegate respondsToSelector:@selector(hitAttentionBtnAction:withItem:withBool:)]) {
        [self.delegate hitAttentionBtnAction:self withItem:item withBool:attenBool];
    }
}
/**
 *@brief 点击话题
 */
- (void)userPublishTableListHitTopicBtnAction:(CTUserPublishTableListView *)view withItem:(CTTopic *)item
{
    if ([self.delegate respondsToSelector:@selector(hitTopicBtnAction:withItem:)]) {
        [self.delegate hitTopicBtnAction:self withItem:item];
    }
}



//推荐cell回调

/**
 *@brief 点击关注按钮
 */
- (void)userPublishTableListRecommendHitAttentionBtnAction:(CTUserPublishTableListView *) view withItem:(CTUserSuggestionItem *)item
{
    if ([self.delegate respondsToSelector:@selector(recommendHitAttentionBtnAction:withItem:)]) {
        [self.delegate recommendHitAttentionBtnAction:self withItem:item];
    }
}
/**
 *@brief 点击头像
 */
- (void)userPublishTableListRecommendHitHeadAction:(CTUserPublishTableListView *)view withItem:(CTUserSuggestionItem *)item
{
    if ([self.delegate respondsToSelector:@selector(recommendHitHeadAction:withItem:)]) {
        [self.delegate recommendHitHeadAction:self withItem:item];
    }
}

@end
